home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SPACE 2
/
SPACE - Library 2 - Volume 1.iso
/
apps
/
136
/
applic
/
column.c
next >
Wrap
C/C++ Source or Header
|
1987-05-12
|
2KB
|
86 lines
/********************************************************************
;
; file: column.c
; version: V1.0 4/4/87 by Mike Sucher
; description: Read in a text file line by line and produce
; a 2-column output.
;
********************************************************************/
#include <stdio.h>
#define WIDTH 80
#define LENGTH 66
#define MARGIN 5
#define GAP 3
main()
{
FILE *input,*output;
int brk,i,j,tot,toti,toto;
char line[WIDTH],buf[LENGTH][WIDTH];
char infile[50],outfile[50];
printf("Column formatting program V1.0 4/87 by Mike Sucher\n\n");
printf("Enter name of input file: ");gets(infile);putchar('\n');
if (!(input = fopen(infile,"r"))) {
printf("Error opening %s for input. Exitting.\n",infile);
printf("Press Return: ");gets(line);
exit(1);
}
printf("Enter name of output file: ");gets(outfile);putchar('\n');
putchar('\n');
if (!(output = fopen(outfile,"w"))) {
printf("Error opening %s for output. Exitting.\n",outfile);
printf("Press Return: ");gets(line);
exit(1);
}
brk = 0;
toti = toto = 0;
while(!brk) {
for(i=0;i<LENGTH;i++) {
for(j=0;j<WIDTH-1;j++) buf[i][j] = ' ';
buf[i][WIDTH-1]=0;
}
tot = 0;
for(i=GAP;i<LENGTH-GAP;i++) {
if(fgets(line,WIDTH,input)) {
line[strlen(line)-1] = 0;
line[WIDTH/2] = 0;
strcpy(&buf[i][MARGIN],line);
buf[i][MARGIN+strlen(line)] = ' ';
}
else {
brk++;break;
}
}
tot += i-GAP;
for(i=GAP;i<LENGTH-GAP;i++) {
if(fgets(line,WIDTH,input)) {
line[strlen(line)-1] = 0;
line[WIDTH/2] = 0;
strcpy(&buf[i][MARGIN+(WIDTH/2)],line);
}
else {
brk++;break;
}
}
tot += i-GAP; toti += tot;
tot = 0;
for(i=0;i<GAP;i++) fputc('\n',output);
for(i=GAP;i<LENGTH-GAP;i++) fprintf(output,"%s\n",buf[i]);
tot += i;
for(i=0;i<GAP;i++) fputc('\n',output);
tot += i; toto += tot;
}
fclose(input);
fclose(output);
printf("%d lines read in from '%s'\n",toti,infile);
printf("%d lines output to '%s'\n",toto,outfile);
printf("Press Return to continue: ");gets(line);
exit(0);
}